﻿<presentation:UserControlView x:Class="Chronos.Client.Win.Views.Units.Exceptions.View"
                              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                              xmlns:presentation="clr-namespace:Rhiannon.Windows.Presentation;assembly=Rhiannon.Windows"
                              xmlns:controls="clr-namespace:Chronos.Client.Win.Controls"
                              xmlns:commanding="clr-namespace:Rhiannon.Windows.Presentation.Commands;assembly=Rhiannon.Windows"
                              xmlns:behaviors="clr-namespace:Rhiannon.Windows.Presentation.Behaviors;assembly=Rhiannon.Windows"
                              x:Uid="Profiler_Unit_ExceptionsView">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="3" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ListView Grid.Row="0" ItemsSource="{Binding Units}" SelectedItem="{Binding SelectedUnit}" IsSynchronizedWithCurrentItem="True"
                  behaviors:GridViewSort.AutoSort="True"
                  VirtualizingStackPanel.IsVirtualizing="True">
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Margin" Value="0,0,0,5"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType= "{x:Type GroupItem}">
                                        <Expander IsExpanded="False" BorderThickness="0,0,0,1">
                                            <Expander.Header>
                                                <Border BorderThickness="0,0,0,1" Background="#AAAAAA" HorizontalAlignment="Stretch">
                                                    <Grid>
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="2*" />
                                                            <ColumnDefinition Width="1*" />
                                                        </Grid.ColumnDefinitions>
                                                        <TextBlock Grid.Column="0" FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="100"/>
                                                        <TextBlock Grid.Column="1" FontWeight="Bold" Text="{Binding Path=ItemCount, StringFormat=' {0} Items'}"/>
                                                    </Grid>
                                                </Border>
                                            </Expander.Header>
                                            <Expander.Content>
                                                <ItemsPresenter />
                                            </Expander.Content>
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListView.GroupStyle>
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}" behaviors:GridViewSort.PropertyName="Id" />
					<GridViewColumn Header="Type" DisplayMemberBinding="{Binding Name}" behaviors:GridViewSort.PropertyName="Name" />
                    <GridViewColumn Header="Thread Id" DisplayMemberBinding="{Binding ThreadId}" behaviors:GridViewSort.PropertyName="Thread.Id" />
                    <GridViewColumn Header="Catched" DisplayMemberBinding="{Binding IsCatched}" behaviors:GridViewSort.PropertyName="IsCatched" />
                    <GridViewColumn Header="Handling time" DisplayMemberBinding="{Binding Lifetime}" behaviors:GridViewSort.PropertyName="Lifetime" />
                </GridView>
            </ListView.View>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Call Tree">
                        <MenuItem Header="Go to thrown" commanding:Event.Command="{Binding GoToExceptionInCallTreeCommand}" commanding:Event.CommandParameter="{Binding SelectedUnit}" />
                    </MenuItem>
                </ContextMenu>
            </ListView.ContextMenu>
        </ListView>
        
        <GridSplitter Grid.Row="1" Height="3" HorizontalAlignment="Stretch" />
        
		<Grid Grid.Row="2">
            <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                <ItemsControl ItemsSource="{Binding Stack}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </Grid>
        
        <Grid Grid.Row="3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0" x:Uid="UnitCollectionView_FilterTextBlock" VerticalAlignment="Center" FontFamily="Verdana" />
            <TextBox Grid.Column="1" Text="{Binding SelectedUnitFilter.Value, UpdateSourceTrigger=PropertyChanged}" />
            <ComboBox Grid.Column="2" ItemsSource="{Binding UnitFilters}" SelectedItem="{Binding SelectedUnitFilter}" DisplayMemberPath="DisplayName" />
            <!--<Button Grid.Column="3" x:Uid="UnitCollectionView_ReloadUnitsButton" Command="{Binding ReloadUnitsCommand}" />-->
        </Grid>
    </Grid>
</presentation:UserControlView>
